import unittest
from time import sleep

from selenium import webdriver

from parameterized import parameterized
from bookshop_po.page.page_login import PageLogin
from bookshop_po.util import read_json


class TestLogin(unittest.TestCase):
    def setUp(self) -> None:
        self.driver=webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.get("http://localhost:8080/bookmall/e/login.jsp")
        self.login=PageLogin(self.driver)

    def tearDown(self) -> None:
        sleep(3)
        self.driver.quit()

    @parameterized.expand(read_json("login.json","login"))
    def test01_login(self,phone,word,expect_text):
        try:
            self.login.page_login(phone,word)
            nickname=self.login.page_get_nickname()
            print("nickname:",nickname)
            self.assertEqual(nickname,expect_text)
        except Exception as e:
            print("出现错误：",e)